package com.itheima.controller;

import com.itheima.anno.Log;
import com.itheima.common.PageBean;
import com.itheima.common.R;
import com.itheima.dto.CheckitemDto;
import com.itheima.dto.CustomerDto;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckitemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.CrossOrigin;

//@CrossOrigin

/**
 * 检查项
 */
@CrossOrigin (value = "*", methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE})
@RestController
@Slf4j
@RequestMapping ("/checkItem")

public class CheckitemController {
    @Autowired
    private CheckitemService checkitemService;


    /**
     * 检查项分页条件查询
     *
     * @param checkitemDto 条件
     * @return R
     */
    @GetMapping ("/pageQuery")
    public R pageQuery(CheckitemDto checkitemDto) {
        PageBean pageBean = checkitemService.pageQuery(checkitemDto);
        return R.ok(pageBean);
    }


    /**
     * 添加检查项
     *
     * @param checkItem 添加项
     * @return R
     */
    @Log
    @PostMapping
    public R add(@RequestBody CheckItem checkItem) {
        checkitemService.add(checkItem);
        return R.ok();
    }

    /**
     * 根据id查询
     *
     * @param id 检查项主键
     * @return R
     */
    @GetMapping ("/{id}")
    public R selectById(@PathVariable Integer id) {
        CheckItem checkItem = checkitemService.selectById(id);
        return R.ok(checkItem);
    }


    /**
     * 修改操作
     *
     * @param checkItem 数据
     * @return R
     */
    @PutMapping
    @Log
    public R updateData(@RequestBody CheckItem checkItem) {
        checkitemService.updateData(checkItem);
        return R.ok();
    }

    /**
     * 根据id删除数据
     *
     * @param id 检查项主键
     * @return R
     */
    @Log
    @DeleteMapping ("/{id}")
    public R deleteById(@PathVariable Integer id) {
        checkitemService.deleteById(id);
        return R.ok();
    }
}
